package com.lonely.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.lonely.common.core.domain.Select;
import com.lonely.common.core.domain.api.R;
import com.lonely.system.domain.entity.SysFactory;
import com.lonely.system.domain.dto.factory.SysFactoryStatQueryDto;
import com.lonely.system.domain.dto.factory.SysFactorySubmitDto;
import com.lonely.system.domain.vo.system.factory.SplitOrderFactoryLineSelectVo;
import com.lonely.system.domain.vo.system.factory.SysFactoryStatsVo;
import com.lonely.system.service.ISysFactoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 黄志标
 * @date: 2025/5/27 11:36
 * @description: 工厂管理处理类
 */
@RestController
@RequestMapping("/systemManage/factory")
@Api(tags = "系统管理/工厂管理")
public class SysFactoryController {

    @Autowired
    private ISysFactoryService sysFactoryService;


    /**
     * 创建公司
     *
     * @param companySubmitDto
     * @return
     */
    @PostMapping("/create")
    @SaCheckPermission("system:factory:create")
    @ApiOperation(value = "创建工厂")
    public R<Boolean> create(@RequestBody @Validated SysFactorySubmitDto companySubmitDto) {
        this.sysFactoryService.create(companySubmitDto);
        return R.status(true);
    }

    /**
     * 编辑公司
     *
     * @param companySubmitDto
     * @return
     */
    @PostMapping("/edit")
    @SaCheckPermission("system:factory:edit")
    @ApiOperation(value = "编辑工厂")
    public R<Boolean> edit(@RequestBody @Validated SysFactorySubmitDto companySubmitDto) {
        this.sysFactoryService.edit(companySubmitDto);
        return R.status(true);
    }


    /**
     * 工厂统计
     *
     * @return
     */
    @PostMapping("/stat")
    @ApiOperation(value = "获取工厂统计信息")
    public R<SysFactoryStatsVo> stat(@RequestBody SysFactoryStatQueryDto queryDto) {
        return R.data(this.sysFactoryService.stat(queryDto));
    }

    /**
     * 获取工厂信息
     *
     * @param factoryId
     * @return
     */
    @GetMapping("/detail/{factoryId}")
    @ApiOperation(value = "获取工厂信息")
    public R<SysFactory> detail(@PathVariable("factoryId") Long factoryId) {
        return R.data(this.sysFactoryService.getById(factoryId));
    }

    /**
     * 暂停工厂分单
     *
     * @param factoryId
     * @return
     */
    @GetMapping("/suspendSplitOrders/{factoryId}")
    @SaCheckPermission("system:factory:suspendSplitOrders")
    @ApiOperation(value = "暂停工厂分单")
    public R<Boolean> suspendSplitOrders(@PathVariable("factoryId") Long factoryId) {
        this.sysFactoryService.suspendSplitOrders(factoryId);
        return R.status(true);
    }

    /**
     * 停用工厂
     *
     * @param factoryId
     * @return
     */
    @GetMapping("/stopUsing/{factoryId}")
    @SaCheckPermission("system:factory:stopUsing")
    @ApiOperation(value = "停用工厂")
    public R<Boolean> stopUsing(@PathVariable("factoryId") Long factoryId) {
        this.sysFactoryService.stopUsing(factoryId);
        return R.status(true);
    }


    /**
     * 获取工厂下拉列表
     *
     * @return
     */
    @GetMapping("/getFactorySelectOptions")
    public R<List<Select>> getFactorySelectOptions() {
        return R.data(this.sysFactoryService.getFactorySelectOptions());
    }


    /**
     * 获取分单时候的工厂线路选择列表
     *
     * @return
     */
    @GetMapping("/getSplitOrderFactoryLineSelectOptions")
    public R<SplitOrderFactoryLineSelectVo> getSplitOrderFactoryLineSelectOptions() {
        return R.data(this.sysFactoryService.getSplitOrderFactoryLineSelectOptions());
    }

}
